package net.lab1024.sa.admin.module.business.aps.domain.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

/**
 * APS排程结果VO
 * 用于前端展示排程优化结果
 *
 * @Author 1024创新实验室
 * @Date 2025-01-28
 * @Wechat zhuoda1024
 * @Email lab1024@163.com
 * @Copyright <a href="https://1024lab.net">1024创新实验室</a>
 */
@Data
@Schema(description = "APS排程结果")
public class ApsScheduleResultVO {

    @Schema(description = "解决方案名称")
    private String solutionName;

    @Schema(description = "排程开始时间")
    private String scheduleStartTime;

    @Schema(description = "排程结束时间")
    private String scheduleEndTime;

    @Schema(description = "总任务数")
    private Integer totalTaskCount;

    @Schema(description = "已分配任务数")
    private Integer assignedTaskCount;

    @Schema(description = "未分配任务数")
    private Integer unassignedTaskCount;

    @Schema(description = "资源利用率")
    private Double resourceUtilization;

    @Schema(description = "是否可行解")
    private Boolean feasible;

    @Schema(description = "优化分数")
    private String score;

    @Schema(description = "求解耗时（毫秒）")
    private Long solvingTimeMs;

    @Schema(description = "任务分配列表")
    private List<TaskAssignmentVO> taskAssignments;

    @Schema(description = "资源使用情况")
    private List<ResourceUsageVO> resourceUsages;

    @Schema(description = "时间线视图数据")
    private List<TimelineItemVO> timelineItems;

    /**
     * 任务分配VO
     */
    @Data
    @Schema(description = "任务分配信息")
    public static class TaskAssignmentVO {
        @Schema(description = "任务ID")
        private Long taskId;

        @Schema(description = "任务名称")
        private String taskName;

        @Schema(description = "任务描述")
        private String description;

        @Schema(description = "任务持续时间（分钟）")
        private Integer duration;

        @Schema(description = "优先级")
        private Integer priority;

        @Schema(description = "分配的资源ID")
        private Long assignedResourceId;

        @Schema(description = "分配的资源名称")
        private String assignedResourceName;

        @Schema(description = "开始时间")
        private LocalDateTime startTime;

        @Schema(description = "结束时间")
        private LocalDateTime endTime;

        @Schema(description = "是否已分配")
        private Boolean assigned;

        @Schema(description = "分配状态")
        private String status;

        @Schema(description = "前置任务ID列表")
        private String predecessorTaskIds;
    }

    /**
     * 资源使用情况VO
     */
    @Data
    @Schema(description = "资源使用情况")
    public static class ResourceUsageVO {
        @Schema(description = "资源ID")
        private Long resourceId;

        @Schema(description = "资源名称")
        private String resourceName;

        @Schema(description = "资源类型")
        private String resourceType;

        @Schema(description = "资源容量")
        private Integer capacity;

        @Schema(description = "已分配任务数")
        private Integer assignedTaskCount;

        @Schema(description = "利用率")
        private Double utilizationRate;

        @Schema(description = "工作时间段")
        private List<WorkPeriodVO> workPeriods;
    }

    /**
     * 工作时间段VO
     */
    @Data
    @Schema(description = "工作时间段")
    public static class WorkPeriodVO {
        @Schema(description = "任务ID")
        private Long taskId;

        @Schema(description = "任务名称")
        private String taskName;

        @Schema(description = "开始时间")
        private LocalDateTime startTime;

        @Schema(description = "结束时间")
        private LocalDateTime endTime;

        @Schema(description = "持续时间（分钟）")
        private Integer duration;
    }

    /**
     * 时间线项目VO
     */
    @Data
    @Schema(description = "时间线项目")
    public static class TimelineItemVO {
        @Schema(description = "项目ID")
        private String id;

        @Schema(description = "组别（资源名称）")
        private String group;

        @Schema(description = "内容（任务名称）")
        private String content;

        @Schema(description = "开始时间")
        private LocalDateTime start;

        @Schema(description = "结束时间")
        private LocalDateTime end;

        @Schema(description = "类型")
        private String type;

        @Schema(description = "样式类名")
        private String className;

        @Schema(description = "标题")
        private String title;

        @Schema(description = "任务优先级")
        private Integer priority;
    }
}